<?php
/**
 * Created by PhpStorm.
 * User: THINK
 * Date: 2017/8/26
 * Time: 10:22
 */
namespace Home\Controller;

use Think\Controller;

class MemberController extends Controller
{
    public function index(){
        $value = session('name');
        if (isset($value)) {
            $indexs = M('announce');
            $lists = $indexs->order('posttime desc')->limit(0, 1)->select();
            $this->assign('lists', $lists);
            $index = M('member');
            $list = $index->alias('a')->where("nickname='$value'")->join('xyh_membergroup b on a.groupid = b.id','left')->find();
            $this->assign('list', $list);
            $this->display();
        }
    }
    public function name(){
        $value = session('name');
        if (isset($value)) {
            $indexs = M('announce');
            $lists = $indexs->order('posttime desc')->limit(0, 1)->select();
            $this->assign('lists', $lists);
            $index = M('member');
            $list = $index->where("nickname='$value'")->find();
            $this->assign('list', $list);
            $this->display();
        }
    }
    public function nameedit(){
        $index = M('member');
        if($index->save(I('post.')) !==false){
            session('name',I('nickname'));
            $this->success('修改成功',U('member/name'));
        }else{
           $this->error('修改失败');
        }

    }
    public function person(){
        $value = session('name');
        if (isset($value)) {
            $indexs = M('announce');
            $lists = $indexs->order('posttime desc')->limit(0, 1)->select();
            $this->assign('lists', $lists);
            $index = M('member');
            $list = $index->where("nickname='$value'")->find();
            $this->assign('list', $list);
            $this->display();
        }
    }
    public function personadd(){
        $index = M('member');
        if($index->save(I('post.')) !==false){
            session('name',I('nickname'));
            $this->success('修改成功',U('member/person'));
        }else{
            $this->error('修改失败');
        }
    }
    public function password(){
        $value = session('name');
        if (isset($value)) {
            $indexs = M('announce');
            $lists = $indexs->order('posttime desc')->limit(0, 1)->select();
            $this->assign('lists', $lists);
            $this->display();
        }
    }
    public function passwords(){
        $index = M('member');
        $s = I('post.');
        $s['oldpassword']  = md5($s['oldpassword']);
        $U = $index->find();
        if ($s['oldpassword']  == $U['password'] ){
            if ($s['password'] == $s['repassword']){

            }else{
                echo '<script>alert("两次密码不一致，请重新输入");history.back();</script>';
            }

        }else{
            echo '<script>alert("当前密码输入不正确，请重新输入");history.back();</script>';
        }
    }
    public function loginout(){
        session(null);
        $this->redirect('http://www.xyh1.com/');
    }
}